package com.seeyon.apps.ext.wangtuo2unity.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.seeyon.ctp.organization.po.OrgMember;
import com.seeyon.ctp.organization.po.OrgPrincipal;
import com.seeyon.ctp.util.DBAgent;

@SuppressWarnings("unchecked")
public class UnitySSODaoImpl implements UnitySSODao {

	@Override
	public List<Object> selectPerson() {
		String sql = "from org_member";
		return DBAgent.find(sql);
	}

	@Override
	public List<OrgMember> getMemberByCode(String code) {
		Map<String, Object> params = new HashMap<>();
		params.put("code", code);
		String sql = "from OrgMember where code = :code and deleted =0 and enable=1 and state=1";
		List<OrgMember> results = DBAgent.find(sql, params);
		return results;
	}
	
	@Override
	public List<OrgMember> getMemberByName(String name) {
		Map<String, Object> params = new HashMap<>();
		params.put("name", name);
		String sql = "from OrgMember where name = :name and deleted =0 and enable=1 and state=1";
		List<OrgMember> results = DBAgent.find(sql, params);
		return results;
	}
	
	@Override
	public List<OrgPrincipal> getPrincipaByMemberId(long memberId) {
		Map<String, Object> params = new HashMap<>();
		params.put("memberId", Long.valueOf(memberId));
		String sql = "from OrgPrincipal where memberId =:memberId";
		List<OrgPrincipal> results = DBAgent.find(sql, params);
		return results;
	}

	@Override
	public OrgMember getMemberById(long memberId) {
		OrgMember orgMember = DBAgent.get(OrgMember.class, memberId);
		return orgMember;
	}

}
